package jgl.vajra.operator.part.vehicle.activity;

import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.gyf.immersionbar.ImmersionBar;

import java.util.ArrayList;
import java.util.List;

import jgl.vajra.operator.R;
import jgl.vajra.operator.bean.HomeMechanicsBean;
import jgl.vajra.operator.databinding.ActivityPriceCalculatorBinding;
import jgl.vajra.operator.manager.FragmentManager;
import jgl.vajra.operator.manager.IntentManager;
import jgl.vajra.operator.part.home.fragment.HomeVehicleTypeFragment;
import jgl.vajra.operator.part.home.pop.AccountingMethodPop;
import jgl.vajra.operator.part.home.pop.AllMachineryPop;
import jgl.vajra.operator.part.vehicle.contract.PriceCalculatorContract;
import jgl.vajra.operator.part.vehicle.viewModel.PriceCalculatorViewModel;
import jgl.vajra.operator.widget.databindingadapter.BaseBindingItemPresenter;
import jgl.vajra.operator.widget.databindingadapter.SingleTypeBindingAdapter;
import jgl.vajra.operator.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.operator.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.operator.widget.utils.ToastUtils;
import jgl.vajra.operator.widget.utils.UIUtils;

@CreateViewModel(PriceCalculatorViewModel.class)
public class PriceCalculatorActivity extends BaseMVVMActivity<PriceCalculatorViewModel, ActivityPriceCalculatorBinding> implements PriceCalculatorContract.View, BaseBindingItemPresenter {

    private SingleTypeBindingAdapter adapterMechanics;
    private List<HomeMechanicsBean> listMechanics = new ArrayList<>();
    private AllMachineryPop allMachineryPop;
    private AccountingMethodPop accountingMethodPop;

    @Override
    public int getLayoutId() {
        return R.layout.activity_price_calculator;
    }

    @Override
    public void initView() {
        super.initView();
        mBinding.setView(this);
        ImmersionBar.with(this).statusBarColor(R.color.color_012BB2).navigationBarColor(R.color.white).fitsSystemWindows(true).statusBarDarkFont(false, 0.2f).init();


        mBinding.toolbar.setNavigationIcon(R.drawable.ic_left_arrow_white);
        mBinding.toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


        //机械类型
        // 不可嵌套滑动
        mBinding.recyclerViewMechanics.setNestedScrollingEnabled(false);
        // 取消head 的 recycleView的焦点
        mBinding.recyclerViewMechanics.setFocusableInTouchMode(false);
        //设置布局管理器
        mBinding.recyclerViewMechanics.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        adapterMechanics = new SingleTypeBindingAdapter(this, listMechanics, R.layout.item_price_calculator_mechanics);
        mBinding.recyclerViewMechanics.setAdapter(adapterMechanics);
        adapterMechanics.setItemPresenter(this);

          List<String> titleList = new ArrayList<>();
        titleList.add("40");
        titleList.add("50");
        titleList.add("60");
        titleList.add("200");
        titleList.add(" 260 ");
        List<Fragment> fragmentList = new ArrayList<>();
        for (int i = 0; i < titleList.size(); i++) {
            HomeVehicleTypeFragment listFragment = FragmentManager.getHomeVehicleTypeFragment(i, "挖掘机", titleList.get(i),false);
            fragmentList.add(listFragment);
        }
        mBinding.tabLayout.setCustomViewTabLayoutView(this, titleList, fragmentList);

    }

    //位置
    @Override
    public void onTriangle() {
        //IntentManager.toCityChoiceActivity(this);
    }

    //全部机械
    @Override
    public void onAllMachinery() {
        if (allMachineryPop == null)
            allMachineryPop = new AllMachineryPop(this);
        allMachineryPop.showPopupWindow(mBinding.toolbar);
    }

    //全部车型
    @Override
    public void onAllVehicle() {
        if (allMachineryPop == null)
            allMachineryPop = new AllMachineryPop(this);
        allMachineryPop.showPopupWindow(mBinding.tvAllMachinery);
    }

    //算账方式
    @Override
    public void onSettleAccounts() {
        if (accountingMethodPop == null)
            accountingMethodPop = new AccountingMethodPop(this);
        accountingMethodPop.showPopupWindow(mBinding.tvAllMachinery);
    }

    @Override
    public void onClickMechanics(int position, HomeMechanicsBean itemData) {

    }

    @Override
    public void onItemClick(int position, Object itemData) {

    }
}
